<?php
namespace app\model;

use think\Model;

class BookType extends Model
{
    protected $table = "ea_book_type";

    /**
     * [setWhere description]
     * @since  2022-04-22
     * @author Dai哥
     * @param  array      $data [description]
     * @return [type]           [description]
     */
    public static function setWhere($data)
    {
        $model = self::whereNull('delete_time')->where('status', 1)->order('sort DESC');

        if(isset($data['pid']) && $data['pid'] !== ''){
            $model = $model->where('pid', $data['pid']);
        }

        # 如果 is_som == Y 只查询子类分类
        if(isset($data['is_som']) && $data['is_som'] == 'Y'){
            $model = $model->where('pid', '>', 0);
        }

        return $model;
    }

    /**
     * [getBookTypeList 获取book分类列表]
     * @since  2022-04-22
     * @author Dai哥
     * @param  [type]     $data [description]
     * @return [type]           [description]
     */
    public static function getBookTypeList($data)
    {
        $list = self::setWhere($data)->field('id, pid, name')->select();

        return $list;
    }
}